﻿namespace ConsoleApp4
{
    //4 Expression bodied成员

    internal class Program
    {

        public static void Main(string[] args)
        {
            //方法
            Calculator calculator = new Calculator();
            Console.WriteLine(calculator.Add(10, 13));
            Console.WriteLine("************");
            Person person = new Person();
            person.Name = "shang";
            Console.WriteLine(person.Name);
            Console.WriteLine("************");
            ShoppingCart cart = new ShoppingCart();
            cart[0] = "shang";
            cart[1] = "shou";
            cart[2] = "lai";
            Console.WriteLine($"{cart[0]}{cart[1]}{cart[2]}");
            Console.WriteLine("************");
            Circle circle  = new Circle(6);
            Console.WriteLine($"radius:{circle.Radius}");


        }
    }

    //方法
    class Calculator
    {
        public int Add(int a, int b) => a + b;
    }

    //属性
    class Person
    {
        private string _name;
        public string Name
        {
            get => _name;
            set => _name = value ?? "Unknown";
        }
    }
    //索引器：
    class ShoppingCart
    {
        //private List<string> items = new List<string>();
        private string[] name = new string[10];

        public string this[int index]
        {
            get => name[index];
            set => name[index] = value;
        }
    }
    //构造函数
    class Circle
    {
        public double Radius { get; }

        public Circle(double radius) => Radius = radius;
    }

}